package com.kingint.web.admin.serve.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.kingint.common.unitedresult.K;
import com.kingint.mbg.dto.department.DepartmentQueryParam;
import com.kingint.mbg.dto.department.DepartmentRepairBack;
import com.kingint.mbg.dto.department.DepartmentRepairParam;
import com.kingint.mbg.group.Insert;
import com.kingint.mbg.ser.entity.SerDepartmentRepair;
import com.kingint.web.admin.serve.service.SerDepartmentRepairService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;


/**
 * @描述：部门保修表控制类
 * @作者: wxh
 * @日期: 2020-12-20
 */
@RestController
@RequestMapping("/serDepartmentRepair")
@Api(value = "SerDepartmentRepairController", description = "部门保修表控制层")
@CrossOrigin
public class SerDepartmentRepairController {

    @Resource
    public SerDepartmentRepairService serDepartmentRepairService;

    @ApiOperation(value = "获取部门维修订单信息列表")
    @GetMapping("/getAllDepartmentRepairList")
    public Object getAcceptanceOrder(DepartmentQueryParam queryParam,
                                     @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
                                     @RequestParam(value = "pageSize", defaultValue = "5") Integer pageSize) {
        IPage<SerDepartmentRepair> repairList = serDepartmentRepairService.getAllDepartmentRepairList(queryParam, pageNum, pageSize);
        return K.ok().data(repairList);
    }

    @ApiOperation(value = "后台添加部门维修单")
    @PostMapping("/addDepartmentRepair")
    public Object addDepartmentRepair(@Validated(Insert.class) @RequestBody DepartmentRepairParam departmentRepairParam) {
        int i = serDepartmentRepairService.addDepartmentRepair(departmentRepairParam);
        if (i > 0) {
            return K.ok().data(i);
        }
        return K.error();
    }

    @ApiOperation(value = "后台获取对应维修单的详情信息(传递维修单的id,不是总单的id)")
    @GetMapping("/getDepartmentRepairInfo")
    public Object getDepartmentRepairInfo(@RequestParam(value = "id") Integer id) {
        DepartmentRepairBack repair = serDepartmentRepairService.getDepartmentRepairInfo(id);
        return K.ok().data(repair);
    }

    @ApiOperation(value = "删除对应维修单信息(传递维修单的id,不是总单的id)")
    @GetMapping("/deleteRepairInfo")
    public Object deleteRepairInfo(@RequestParam(value = "id") Integer id) {
        Integer i = serDepartmentRepairService.deleteRepairInfo(id);
        if (i > 0) {
            return K.ok().data(i);
        }
        return K.error();
    }

    @ApiOperation(value = "挂起当前维修单(总单的id)")
    @GetMapping("/hangUpInfo")
    public Object hangUpInfo(@RequestParam(value = "workId") Integer workId) {
        Integer i = serDepartmentRepairService.hangUpInfo(workId);
        if (i > 0) {
            return K.ok().data(i);
        }
        return K.error();
    }

    @ApiOperation(value = "相关人员验收维修工单(总单id)")
    @GetMapping("/checkWorkOrder")
    public Object checkWorkOrder(@RequestParam(value = "workId") Integer workId,
                                 @RequestParam("status") Integer status) {
        Integer i = serDepartmentRepairService.checkWorkOrder(workId,status);
        if (i > 0) {
            return K.ok().data(i);
        }
        return K.error();
    }

    //更换处理人
    @ApiOperation(value = "更换处理人")
    @GetMapping("/changeHandleUser")
    public Object changeHandleUser(@RequestParam(value = "id") Integer id, @RequestParam("memberId") Long memberId) {
        int i = serDepartmentRepairService.changeHandleUser(id, memberId);
        if (i > 0) {
            return K.ok().data(i);
        }
        return K.error();
    }
}